package Sort2;

import java.util.Arrays;

public class shell {
    public static void main(String[] args) {
        int[] arr={5,9,8,1,1,5,4};
        shell(arr);
        System.out.println(Arrays.toString(arr));
    }
    public static void shell(int[] arr){
        int gap=arr.length/2;
        while(gap!=0){
            _shell(arr,gap);
            gap/=2;
        }
    }
    public static void _shell(int[] arr,int gap){
        for(int bound=gap;bound<arr.length;bound+=gap){
            int temp=arr[bound];
            int cur=bound-gap;
            for(;cur>=0;cur-=gap){
                if(arr[cur]>temp){
                    arr[cur+gap]=arr[cur];
                }else{
                    break;
                }
            }
            arr[cur+gap]=temp;
        }
    }
}
